package jp.heartdokyun.model.component;

import java.util.Timer;
import java.util.TimerTask;

import jp.heartdokyun.MainGamePanel;

import android.os.Handler;

public class BehaviorC extends Behavior {
	private static final int rate = 20;
	private static final int maxFrames = 30;
	private static final int maxFrames2 = 60;

	private boolean started = false;
	private int frames = 0;
	private int goalY = 0;
	Handler thandler;
	Boolean run;
	private int nextrate = MainGamePanel.nextrate;
	private String mylevel = MainGamePanel.getLevel;

	public BehaviorC(int speed, int angleSpeed, int distance,int initx, int inity) {
		super(speed, angleSpeed, distance, initx,  inity);
	}


	@Override
	protected void _init() {
		//this.setAcc(((double)(3d * this.getSpeed() * this.getSpeed())) / (double)(2d * this.getDistance()));
		this.setSignY(1);
		mylevel = MainGamePanel.getLevel;
		/*
		Timer timer;
		timer = new Timer(true);
		thandler = new Handler();
		timer.schedule(new TimerTask() {
			public void run() {
				// 表示の更新
				thandler.post(new Runnable() {
					public void run() {
						run = true;

					}
				});
			}
		}, 	1000,1000);
		*/
		
	}
	@Override
	public void caliculateNextPosition(int currentX, int currentY, int width, int height, int bitmapWidth, int bitmapHeight) {

		
		
		if (! started) {
			this.goalY = currentY + this.getSignY() * this.getDistance();
			this.started = true;
		}
		frames++;
		this.setNextY(currentY + (goalY - currentY) / rate);
		this.setNextX(currentX);

		if(mylevel.equals("5"))
		{
			if (frames > maxFrames2) {
				this.setupNext(width, height);
			}
		}
		else
		{
			if (frames > maxFrames) {
				this.setupNext(width, height);
			}
		}
	}

	protected void setupNext(int width, int height) {
		frames = 0;
		this.setNextX((int) (Math.random() * width));
		if(mylevel.equals("5")||mylevel.equals("4"))
		{
			this.setNextY((int)((Math.random() * 200)+190));

		}
		else
		{
			this.setNextY((int)(Math.random() * (height - this.getSignY() * this.getDistance())));

		}
		
		
		this.goalY = this.getNextY() + this.getSignY() * this.getDistance();
	}
}